package com.my.drools;

import com.my.drools.entity.Account;
import com.my.drools.util.CreateDroolsFile;
import com.my.drools.util.KnowledgeSessionHelper;
import com.my.drools.util.OutputDisplay;
import org.drools.core.impl.KnowledgeBaseFactory;
import org.kie.api.io.ResourceType;
import org.kie.api.runtime.KieContainer;
import org.kie.api.runtime.KieSession;
import org.kie.api.runtime.StatelessKieSession;
import org.kie.internal.builder.KnowledgeBuilder;
import org.kie.internal.builder.KnowledgeBuilderError;
import org.kie.internal.builder.KnowledgeBuilderErrors;
import org.kie.internal.builder.KnowledgeBuilderFactory;
import org.kie.internal.io.ResourceFactory;
import org.kie.internal.runtime.StatefulKnowledgeSession;
import org.kie.internal.utils.KieHelper;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.TimerTask;

/**
 * @Description
 * @Author 36549
 * @Date 2019/7/24
 * @Version V1.0.0
 * @Update 更新说明
 */
public class Test extends TimerTask {
    StatelessKieSession statelessKieSession = null;
    KieSession sessionStatefull = null;
    static KieContainer kieContainer;
    static int i=0;

    @Override
    public void run() {
        i++;
        KieHelper helper = new KieHelper();
        try {
            helper.addContent(CreateDroolsFile.createDroolsFile("1232432432=========","333"), ResourceType.DRL);
        } catch (IOException e) {
            e.printStackTrace();
        }
        KieSession kieSession = helper.build().newKieSession();
        kieSession.setGlobal("showResults", new OutputDisplay());
        kieSession.insert(new Account());
        kieSession.fireAllRules();
        kieSession.dispose();
        if(i==10){
            StatefulKnowledgeSession kSession = null;
            try {
                KieHelper helper1 = new KieHelper();
                helper1.addContent(CreateDroolsFile.createDroolsFile("adfsf=========","333"), ResourceType.DRL);
                KieSession kieSession1 = helper1.build().newKieSession();
                kieSession1.setGlobal("showResults", new OutputDisplay());
                kieSession1.insert(new Account());
                kieSession1.fireAllRules();
                kieSession1.dispose();
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
